<template>
  <el-container>
    <el-header>
      <div>图书借阅管理系统</div>
      <div>
        登录用户：{{username}}
          <el-tooltip content="点击退出">
            <el-button type="danger"
            size="mini"
            icon="el-icon-user-solid"
            @click="logout"
            circle
            plain>
            </el-button>
          </el-tooltip>
      </div>
    </el-header>

    <el-container>
      <el-aside width="200px">
        <!-- 编写菜单
        router 启用路由
        background-color 默认菜单背景颜色设置
        text-color 默认文字颜色
        active-text-color 激活后文字颜色
        unique-opened 设置菜单只打开一个
        -->
        <el-menu
        router
        background-color="#2B4B6B"
        text-color="#fff"
        active-text-color="#409EFF"
        unique-opened>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-platform"></i>
              <span>馆藏类别管理</span>
            </template>
            <el-menu-item index="/category">
              <i class="el-icon-document-copy"></i>
              <span>类别信息管理</span>
            </el-menu-item>
            <el-menu-item index="/book">
              <i class="el-icon-receiving"></i>
              <span>馆藏图书管理</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>借阅信息管理</span>
            </template>
            <el-menu-item index="/borrow">
              <i class="el-icon-c-scale-to-original"></i>
              <span>借阅信息管理</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-s-tools"></i>
              <span>系统信息管理</span>
            </template>
            <el-menu-item index="/logs">
              <i class="el-icon-s-marketing"></i>
              <span>日志信息管理</span>
            </el-menu-item>
            <el-menu-item index="/users">
              <i class="el-icon-user"></i>
              <span>用户信息管理</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>

      </el-aside>
      <el-main>
        <!-- 路由占位符，控制组件跳转到到main布局中 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    data() {
      return {
        username: sessionStorage.getItem("username")
      }
    },
    methods: {
      logout() {
        this.$http.get("http://114.55.238.138:9000/api/user/logout") //调用后台注销方法
          .then(res => {
            if (res.data.data == 200) {
              sessionStorage.removeItem("username"); //移除sessionStorage中的用户信息
              sessionStorage.clear(); //清空sessionStorage中的用户信息
              this.$router.push('/login'); //跳转到登录页面
            }
          })
          .catch(e => {

          })
      }
    }
  }
</script>

<style scoped>
  .el-header {
    background-color: #2B4B6B;
    display: flex;
    justify-content: space-between;
    padding-left: 10px;
    align-items: center;
    color: white;
    font-size: 18px;
  }

  .el-aside {
    color: white;
    background-color: #2B4B6B;
  }

  .el-main {
    background-color: aliceblue;
  }

  .el-container {
    height: 100%;
  }
</style>
